from flask import Blueprint, send_from_directory
from controllers.detection_controller import run_web_detection, run_mysql_detection, list_mysql_reports, list_web_reports, get_mysql_report_content, get_web_report_content
import os

detection_bp = Blueprint('detection', __name__)

# Web缺陷识别路由
@detection_bp.route('/web', methods=['POST'])
def web_detection():
    return run_web_detection()

# MySQL缺陷识别路由
@detection_bp.route('/mysql', methods=['POST'])
def mysql_detection():
    return run_mysql_detection()

# 获取MySQL报告列表
@detection_bp.route('/mysql/reports', methods=['GET'])
def mysql_reports():
    return list_mysql_reports()

# 获取Web报告列表
@detection_bp.route('/web/reports', methods=['GET'])
def web_reports():
    return list_web_reports()

# 获取MySQL报告内容
@detection_bp.route('/mysql/reports/<filename>', methods=['GET'])
def mysql_report_content(filename):
    return get_mysql_report_content(filename)

# 获取Web报告内容
@detection_bp.route('/web/reports/<filename>', methods=['GET'])
def web_report_content(filename):
    return get_web_report_content(filename)